package gui;

import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;

import dbConnection.Database;

public class MainScreen extends JFrame {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public LoginScreen login;
    public JScrollPane uSearch;
    public JScrollPane admin;
    public static Database DB;
    
    public static void main(String[] args) {
    	DB = new Database();
    	
    	try {
    		DB.connect();
    	} catch (Exception e) {
    		e.printStackTrace();  // for now
    	}  
    	
    	new MainScreen(); 
    	  	
    }
    
    public MainScreen() {
	
//	setMinimumSize(new Dimension(900,500));
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	showLogin();
	pack();
	setLocation(300,200);
	setVisible(true);
    }
    
    //user view and search are 2 separate tabs
    public void showUserView(int userID) {
    	setMinimumSize(new Dimension(900,500));
    	getContentPane().removeAll();
    	setTitle("Library Database: User View");
    	uSearch = new JScrollPane(new UserSearch(DB, userID, this), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    	add(uSearch);
    	validate();
//    	repaint();
    	
    }
    
    //Admin user and item search are 2 separate tabs
    public void showAdminView() {
    setMinimumSize(new Dimension(900,500));
    
	getContentPane().removeAll();
	setTitle("Library Database: Admin View");
    	admin = new JScrollPane(new AdminView(this,DB), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    	add(admin);
    	validate();
//    	repaint();
    }
    
    //show or return to login screen
    public void showLogin() {
	setTitle("Library Database: Login");
	setMinimumSize(new Dimension(200,200));
	setSize(200,200);
	getContentPane().removeAll();
	login = new LoginScreen(this, DB);
	add(login);
	validate();
	login.requestFocusInWindow();
    }
}

